package com.sanchunhui.psc.presenter

import com.sanchunhui.psc.data.protocol.ResponseInfo
import com.sanchunhui.psc.data.protocol.UserInfo
import com.sanchunhui.psc.ext.excute
import com.sanchunhui.psc.presenter.view.SearchMemberView
import com.sanchunhui.psc.rx.BaseSubscriber
import com.sanchunhui.psc.service.ProjectTeamService
import javax.inject.Inject

/**
 * @Author zyx
 * @Date 2021/7/13-15:02
 * @Dscribe
 */
class SearchMemberPresenter @Inject constructor() : BasePresenter<SearchMemberView>() {

    @Inject
    lateinit var teamService: ProjectTeamService

    /*
        获取分组下所有成员
     */
    fun  getSearchMember(token: String, name: String?=null, company_id:Int?=null,job_id:Int?=null) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        teamService.getSearchMember(token,name,company_id,job_id).excute(object : BaseSubscriber<MutableList<UserInfo>?>(mView) {
            override fun onNext(t: MutableList<UserInfo>?) {
                mView.onGetSearchMemberResult(t)
            }
        }, lifecycleProvider)
    }

    /*
         添加成员到指定分组
     */
    fun addTeamMember(teamId: Int, token: String, ads: List<Int>) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        teamService.addTeamMember(teamId, token, ads)
            .excute(object : BaseSubscriber<Boolean>(mView) {
                override fun onNext(t: Boolean) {
                    mView.onGetAddTeamMemberResult(t)
                }
            }, lifecycleProvider)

    }

    /*
        获取所有公司组成的映射（键值对）
     */
    fun getCompanyList(token: String) {
        if (!checkNetWork()) {
            return
        }
        teamService.getCompanyList(token)
            .excute(object : BaseSubscriber<ResponseInfo>(mView) {
                override fun onNext(t: ResponseInfo) {
                    mView.onGetComanyListResult(t)
                }
            }, lifecycleProvider)

    }

    /*
        获取所有⼯种组成的映射（键值对）
    */
    fun getJobList(token: String) {
        if (!checkNetWork()) {
            return
        }
        teamService.getJobList(token)
            .excute(object : BaseSubscriber<ResponseInfo>(mView) {
                override fun onNext(t: ResponseInfo) {
                    mView.onGetJobListResult(t)
                }
            }, lifecycleProvider)

    }



}